package ess.control;

public class ElevatorStateOpening extends ElevatorState {

	public ElevatorStateOpening(ElevatorProxy proxy) {
		super(proxy, STATE_OPENING);
	}

	public void processState() {
		proxy.open();
		if (proxy.hasRemainedRequestWithSameDirection()==true) {
			proxy.removeAllElevatorRequest();
		}
		if(proxy.isTopBottom()){
			if(proxy.getDirection() == Direction.UP){
				proxy.changeDirection(Direction.DOWN);
			}
			else{
				proxy.changeDirection(Direction.UP);
			}
		}
		proxy.activateObstacleButton(true);
	}

	public ElevatorState handleCommand(Command c) {
		if(c.equals(Command.COMMAND_DOOR_STOP))
		{
			return proxy.getState(STATE_OPENED);
		}
		if(c.equals(Command.COMMAND_DOOR_CLOSE))
		{
			return proxy.getState(STATE_CLOSING);
		}
		return null;
	}

}
